/**
 * @Title: HomeActivity.java
 * @Package com.sinoglobal.waitingMe.activity
 * @Description: TODO(用一句话描述该文件做什么)
 * @author hpq
 * @date 2015-8-30 上午11:55:09
 */

package com.sinoglobal.wallet.activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.sinoglobal.wallet.R;
import com.sinoglobal.wallet.api.RemoteImpl;
import com.sinoglobal.wallet.app.SinoConstans;
import com.sinoglobal.wallet.app.SinoValueManager;
import com.sinoglobal.wallet.entity.W_HomeBalanceEntity;
import com.sinoglobal.wallet.entity.W_HomeBalanceEntity.RsEntity;
import com.sinoglobal.wallet.task.MyAsyncTask;

/**
 * @author clf
 * @createdate 2015-10-22
 * @Description: TODO(钱包入口)
 */
public class W_MainActivity extends W_SinoBaseActivity  {

	private RelativeLayout my_wallet_layout,submit_order;
	private TextView mywallet_prompt_txt,mywallet_right_red_dot;
	private RsEntity rs;
	private EditText submit_userId;
	private Button submit_userId_but,home_fragment;
	@Override
	protected void onCreate(Bundle arg0) {
		super.onCreate(arg0);
		setContentView(R.layout.wallet_activity_first_main);
		mTemplateTitleText.setText("入口");
		SinoValueManager.getInstance().clearIdProductPhone(this);
	//	SinoValueManager.getInstance().setIdProductPhone(this, "98634","XN01_SINOSNS_QYY","18811739209");
	//	SinoValueManager.putValue(this, SinoConstans.KEY_PRODUCT_ID, "XN01_SINOSNS_QYY", true);
		init();
	}
	private void init() {
		my_wallet_layout = (RelativeLayout)findViewById(R.id.my_wallet_layout);
		submit_order = (RelativeLayout)findViewById(R.id.submit_order);
		mywallet_prompt_txt = (TextView)findViewById(R.id.mywallet_prompt_txt);
		mywallet_right_red_dot = (TextView)findViewById(R.id.mywallet_right_red_dot);
		submit_userId = (EditText) findViewById(R.id.submit_userId);
		submit_userId_but = (Button) findViewById(R.id.submit_userId_but);
		home_fragment = (Button) findViewById(R.id.home_fragment);
		my_wallet_layout.setOnClickListener(this);
		home_fragment.setOnClickListener(this);
		submit_order.setOnClickListener(this);
		submit_userId_but.setOnClickListener(this);
	}
	@Override
	public void onClick(View v) {
		int id = v.getId();
		if(id==R.id.my_wallet_layout){
			mywallet_right_red_dot.setVisibility(View.GONE);
		/*	Bundle bundle = new Bundle();
			if(rs!=null){

				bundle.putString("Balance", rs.getBalance());
				bundle.putString("IsHasPass", rs.getIsHasPass());
				bundle.putInt("BankCardNum", rs.getBankCardNum());
				bundle.putString("BalanceChange", rs.getBalanceChange());
			}*/

			goIntent("com.sinoglobal.wallet.home");//跳转到主页面
		}else if(id==R.id.submit_order){
			goIntent(W_GoodsDetailsActivity.class);//跳转到商品详情页
		}else if(id == R.id.submit_userId_but){//提交UserId
			
			SinoValueManager.putValue(this, SinoConstans.KEY_PRODUCT_ID, "XN01_ZTTV_HZT", true);//产品标识
			
			if(submit_userId.getText().toString().equals("")){
				showToast("UserId：" + "98634");
			}else{
				SinoValueManager.putValue(this, SinoConstans.KEY_USER_ID, submit_userId.getText().toString().trim(), true);//userId
				showToast("UserId：" + submit_userId.getText().toString());
			}
			getData();
			
		}else if(id==R.id.wallet_noData){
			loadError(false);
		}else if(id==R.id.home_fragment){
			goIntent(W_FragmentHomeActivity.class);//跳转到商品详情页
		}
	}
	private void getData() {
		MyAsyncTask<W_HomeBalanceEntity> task = new MyAsyncTask<W_HomeBalanceEntity>(true,this,true) {
			@Override
			public W_HomeBalanceEntity before(Void... params) throws Exception {
				return RemoteImpl.getInstance().getBalance(W_MainActivity.this);
			}

			@Override
			public void after(W_HomeBalanceEntity result) {
				if (result != null) {
					if (result.getCode().equals("100")) {
						rs=result.getRs();
						if(rs.getBalanceChange() != null){
							if(rs.getBalanceChange().equals("N")){
								mywallet_prompt_txt.setText("");
							}else{
								mywallet_right_red_dot.setVisibility(View.VISIBLE);
								mywallet_prompt_txt.setText("余额");
							}
						}
					}else{
						showToast("数据加载失败");
					}
				}

			}

			@Override
			public void exception() {
			}
		};
		task.execute();
	}
	
	
	public void couponDetail(View v) {
		goIntent(W_CouponDetailActivity.class);
	}
	
	

}
